 $(function() {	
    $(".datepicker").datepicker({
	   dateFormat:"yy-mm-dd",
	   showOn: "button",
	   buttonImage: link+"public/images/calendar.gif",
	   buttonImageOnly: true,
	   minDate: 0});
 });
	var current=0;
	function slidebox(slideid){
		if(parseInt(current)==slideid) return;
		
		if((slideid-parseInt(current))==1){		
			$('#slidebox'+parseInt(current)).animate({left:"-=785"},1500).animate({left:"+=200"},2000).addClass('cursor_poiter');	
			$("#slidebox"+slideid).removeClass("cursor_poiter");	
			$("#img1slidebox"+slideid).show();
			$("#img2slidebox"+slideid).hide();
			$("#boxslidebox"+slideid).show();
			$("#h3slidebox"+slideid).hide();	
			
			$('#img1slidebox'+parseInt(current)).animate({opacity:0.5},1500).hide(1500);
			$('#img2slidebox'+parseInt(current)).show(2000);
			$("#boxslidebox"+parseInt(current)).hide(1500);
			$('#h3slidebox'+parseInt(current)).show(2000);
		}else 
		if((slideid-parseInt(current))==2){
			$('#slidebox'+parseInt(current)).animate({left:"-=785"},1500).animate({left:"+=200"},2000).addClass('cursor_poiter');
			$('#slidebox'+(parseInt(current)+1)).animate({left:"-=785"},1500).animate({left:"+=200"},2000);
			$('#slidebox'+slideid).removeClass("cursor_poiter");
			$('#img1slidebox'+slideid).show().animate({opacity:1},2000);
			$('#img2slidebox'+slideid).hide();
			$("#boxslidebox"+slideid).show();
			$("#h3slidebox"+slideid).hide();
						
			$('#img1slidebox'+parseInt(current)).animate({opacity:0.5},1500).hide(1500);
			$('#img2slidebox'+parseInt(current)).show(2000);
			$("#boxslidebox"+parseInt(current)).hide(1500);
			$('#h3slidebox'+parseInt(current)).show(2000);
		}else if(slideid-parseInt(current)==-1){
			$('#slidebox'+slideid).removeClass("cursor_poiter").animate({left:"+=785"},1500).animate({left:"-=200"},2000);
			$('#img1slidebox'+slideid).show().animate({opacity:1},2000);
			$('#img2slidebox'+slideid).hide();
			$("#boxslidebox"+slideid).show();
			$("#h3slidebox"+slideid).hide();
			
			$('#slidebox'+parseInt(current)).addClass('cursor_poiter').animate({left:"+=200"},1500).animate({left:"-=200"},2000);
			$('#img1slidebox'+parseInt(current)).animate({opacity:0.5},1500).hide(1500);
			$('#img2slidebox'+parseInt(current)).show(2000);
			$("#boxslidebox"+parseInt(current)).hide(1500);
			$('#h3slidebox'+parseInt(current)).show(2000);
		}else if(slideid-parseInt(current)==-2){
			$('#slidebox'+slideid).removeClass('cursor_poiter').animate({left:"+=785"},1500).animate({left:"-=200"},1500);	
			$('#img1slidebox'+slideid).show().animate({opacity:1},2500);
			$('#img2slidebox'+slideid).hide();
			$("#boxslidebox"+slideid).show();
			$("#h3slidebox"+slideid).hide();
			
			$('#slidebox'+(parseInt(current)-1)).animate({left:"+=785"},1500).animate({left:"-=200"},1500);	
			$('#slidebox'+parseInt(current)).animate({left:"+=200"},1500).animate({left:"-=200"},1500).addClass('cursor_poiter');
			$('#img1slidebox'+parseInt(current)).animate({opacity:0.5},1500).hide(1500);
			$('#img2slidebox'+parseInt(current)).show(2500);
			$("#boxslidebox"+parseInt(current)).hide(1500);
			$('#h3slidebox'+parseInt(current)).show(2500);
		}
		current=slideid;			
	};
	function RightClick(idnumberpage,idtotalpage,idnameboxoutsize,namepager,namearray){	

		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 0 && numberpage < total){
			var rightclick=numberpage+1;			
			if(namearray[rightclick]==false){	
				$.get(link+'home/ajax/'+namepager+'?pagenumber='+rightclick,function(data){		
					document.getElementById(idnameboxoutsize).innerHTML+=data;			
				});				
			}
			$("#"+idnumberpage).html(numberpage+1);
			$("#"+idnameboxoutsize).css('width',289*3*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=-867'},1200);
			namearray[rightclick]=true;			
		}
	}
    function RightClick2(idnumberpage,idtotalpage,idnameboxoutsize,namepager,namearray){
		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 0 && numberpage < total){        
			var rightclick=numberpage+1; 
			if(namearray[rightclick]==false){
                $.get(link+'home/ajax/'+namepager+'?pagenumber='+rightclick,function(data){		
                document.getElementById(idnameboxoutsize).innerHTML+=data;		                    
			});				
			}
			$("#"+idnumberpage).html(numberpage+1);
			$("#"+idnameboxoutsize).css('width',220*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=-220'},1200);
			namearray[rightclick]=true;			
		}
	}
	
	function RightClick3(idnumberpage,idtotalpage,idnameboxoutsize,namepager,namearray,description,fromdate,todate,numberroom,numberadult,numberchild){
		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 0 && numberpage < total){        
			var rightclick=numberpage+1; 
			if(namearray[rightclick]==false){
                $.post(link+'home/ajax/'+namepager+'?pagenumber='+rightclick,{des:description,from:fromdate,to:todate,room:numberroom,adult:numberadult,child:numberchild},function(data){		
                document.getElementById(idnameboxoutsize).innerHTML+=data;		                    
			});				
			}else{
				
			}
			$("#"+idnumberpage).html(numberpage+1);
			$("#"+idnameboxoutsize).css('width',660*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=-660'},1200);
			namearray[rightclick]=true;			
		}
	}
	
	function LeftClick(idnumberpage,idtotalpage,idnameboxoutsize){				
		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 1 && numberpage <= total){
			$("#"+idnumberpage).html(numberpage-1);
			$("#"+idnameboxoutsize).css('width',289*3*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=867'},1200);
		}
	}
    function LeftClick2(idnumberpage,idtotalpage,idnameboxoutsize){				
		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 1 && numberpage <= total){
			$("#"+idnumberpage).html(numberpage-1);
			$("#"+idnameboxoutsize).css('width',220*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=220'},1200);
		}
	}
	function LeftClick3(idnumberpage,idtotalpage,idnameboxoutsize){				
		var numberpage=parseInt($("#"+idnumberpage).html());
		var total=parseInt($("#"+idtotalpage).html());
		if(numberpage > 1 && numberpage <= total){
			$("#"+idnumberpage).html(numberpage-1);
			$("#"+idnameboxoutsize).css('width',660*total).removeClass("item");
			$("#"+idnameboxoutsize).animate({'left':'+=660'},1200);
		}
	}
	
	function loaddata(page,idnameboxoutsize,postdata,idnumberpage,idtotalpage,namepager,namearray){
			for(var i=1;i<=page;i++){
				if(namearray[i]==false){
					//load dữ liệu ajax rồi cộng vào html
					$.post(link+'home/ajax/'+namepager+'?pagenumber='+page,postdata,function(data){		
					document.getElementById(idnameboxoutsize).innerHTML+=data;		                    
					});	
					namearray[i]=true;
				}else{
					
				}
				
			}
			//hiển thị page đúng		
						
			if($("#"+idnumberpage).html()<page){
				$("#"+idnameboxoutsize).css('width',660*$('#'+idtotalpage).html()).removeClass("item");
				$("#"+idnameboxoutsize).animate({'left':'-='+(660*(page-$("#"+idnumberpage).html()))},1200);
			}else if($("#"+idnumberpage).html()>page){
				$("#"+idnameboxoutsize).animate({'left':'+='+(660*($("#"+idnumberpage).html()-page))},1200);
			}
			$("#"+idnumberpage).html(page);
			
		}
	
	function MPActivities(idnumber){
		for(var i=1;i<7;i++){
			if(i==idnumber) $("#mpa"+i).addClass('active');
			else $("#mpa"+i).removeClass('active');
		}
	}
	
	function DetailHotel(idname,idhotel,ajaxname,from,to){
		$.get(link+'home/ajax/'+ajaxname+'?'+idname+'='+idhotel+'&from='+from+'&to='+to,function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});
		
	} 
	
	function DetailHotelRoom2(idroomnamelink,idroom,idhotelnamelink,idhotel,ajaxname){
		$.get(link+'home/ajax/'+ajaxname+'?'+idroomnamelink+'='+idroom+'&'+idhotelnamelink+'='+idhotel,function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});
		
	}
	
	function DetailRestaurant(idrestaurant,iddate,idmeal,idpax){
		$.get(link+'home/ajax/getajax_book_restaurant?idrestaurant='+idrestaurant+'&date='+$('#'+iddate).val()+'&meal='+$('#'+idmeal).val()+'&pax='+$('#'+idpax).val(),function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});
	}
	
	function DetailActivity(idactivity,iddate,idmeal,idadult,idchild){
		$.get(link+'home/ajax/getajax_book_activity?idactivity='+idactivity+'&datefrom='+$('#'+iddate).val()+'&meal='+$('#'+idmeal).val()+'&adult='+$('#'+idadult).val()+'&child='+$('#'+idchild).val(),function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});
	}
	
	function DetailPackage(idpackage,from,adult,child){
		
		$.get(link+'home/ajax/getajax_book_package?idpackage='+idpackage+'&from='+from+'&adult='+adult+'&child='+child,function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
				$('.datepicker').datepicker();
			}
		});
		
	} 
	
	function DetailGuild(idguild,iddate,idtime,idgroup){	
		$.get(link+'home/ajax/getajax_book_guild?idguild='+idguild+'&date='+$('#'+iddate).val()+'&time='+$('#'+idtime).val()+'&group='+$('#'+idgroup).val(),function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});
	}
	
	function DetailCar(idcar,provide,service,type,fromdate,todate){
		$.get(link+'home/ajax/getajax_book_car?idcar='+idcar+'&provide='+provide+'&service='+service+'&type='+type+'&fromdate='+fromdate+'&todate='+todate,function(data){
			if(data!=null){
			    document.getElementById("boxbookingdetailhotel").innerHTML=data;
			    $("#typeofdvposition").show();
			    $("#boxbookingdetailhotel").show();
		    }
		    $('*[name=timearrive]').appendDtpicker();
			$('*[name=timedeparture]').appendDtpicker();
	 	});  
	  
	 }
	
	//function DetailCar(idcar,provide,service,type){
//		$.get(link+'home/ajax/getajax_book_car?idcar='+idcar+'&provide='+provide+'&service='+service+'&type='+type,function(data){
//			if(data!=null){
//				document.getElementById("boxbookingdetailhotel").innerHTML=data;
//				$("#typeofdvposition").show();
//				$("#boxbookingdetailhotel").show();
//			}
//		});		
//	}
	
	function DetailFlight(idflight,departfrom,arriveto,adult,child,departuredate){		
		$.get(link+'home/ajax/getajax_book_flight?idflight='+idflight+'&departfrom='+departfrom+'&arriveto='+arriveto+'&adult='+adult+'&child='+child+'&departuredate='+departuredate,function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});		
	}
	
	function BookFlight_RoundTrip(idroundtrip,idoneway,departfrom,arriveto,adult,child,departuredate,returningdate){
		$.get(link+'home/ajax/getajax_book_flight_roundtrip?idroundtrip='+idroundtrip+'&idoneway='+idoneway+'&departfrom='+departfrom+'&arriveto='+arriveto+'&adult='+adult+'&child='+child+'&departuredate='+departuredate+'&returningdate='+returningdate,function(data){			
			if(data!=null){
				document.getElementById("boxbookingdetailhotel").innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxbookingdetailhotel").show();
			}
		});			
	}
	
	function Showpop(idnumber){
		for(var z=1;z<=10;z++){
			if(z==idnumber){
				$("#typeofdvposition").show();
				$("#boxmenu"+z).show();		
				$("#amenu"+z).addClass("active");
			}else{
				$("#boxmenu"+z).hide();		
				$("#amenu"+z).removeClass("active");
				$('#boxbookingdetailhotel').hide();
			}
		}	
	}
	function Showpophotel(idnumber,nameofajax,valueofselect){
		$("#typeofdvposition").show();
		$("#boxmenu"+idnumber).show();		
		$("#amenu"+idnumber).addClass("active");
		$.get(link+'home/ajax/'+nameofajax+'?option='+valueofselect,function(data){
			if(data!=null){
				document.getElementById("boxmenu"+idnumber).innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxmenu"+idnumber).show();
				$(".datepicker").datepicker({
				   dateFormat:"yy-mm-dd",
				   showOn: "button",
				   buttonImage: link+"public/images/calendar.gif",
				   buttonImageOnly: true,
				   minDate: 0});
			}																	
		});
	}
	
	function showpopflight(idnumber,depart,arrive,nameofajax){
		$("#typeofdvposition").show();
		$("#boxmenu"+idnumber).show();		
		$("#amenu"+idnumber).addClass("active");
		$.get(link+'home/ajax/'+nameofajax+'?departfrom='+depart+'&arriveto='+arrive,function(data){
			if(data!=null){
				document.getElementById("boxmenu"+idnumber).innerHTML=data;
				$("#typeofdvposition").show();
				$("#boxmenu"+idnumber).show();
				$('#chkroundtrip').prop('checked',false);		
				$('#chkoneway').prop('checked',false);
				$('#box_returning').hide();
				$('#box_departure').hide();		
				$(".datepicker").datepicker({
				   dateFormat:"yy-mm-dd",
				   showOn: "button",
				   buttonImage: link+"public/images/calendar.gif",
				   buttonImageOnly: true,
				   minDate: 0});
			}																	
		});
	}
	
	function Closepop(idnumber){
		for(var z=1;z<=10;z++){
			$("#typeofdvposition").hide();
			$("#boxmenu"+z).hide();	
			$("#amenu"+z).removeClass('active');
			$('#boxbookingdetailhotel').hide();
		}			
	};
	
	function showbox(idbox){
		$('#'+idbox).removeClass('hide').animate({height:'toggle'},800);
	}
	$(document).ready(function(){
		$(".an").hide();
        $(".hide").hide();
	});
	function showhidebox(idbutton,idbox){
		$('#'+idbutton).toggleClass('tran_180deg mgr14 mgt3');
		$('#'+idbox).animate({height:'toggle'},800);
	}
    function mappop(number){
		for(var i=1;i<5;i++){
			if(i==number){
				$("#amap"+number).removeClass("zindex10").addClass("active");
				$('#tab'+number).addClass('active');
				$('#boxtab'+number).show();
				$("#imgmap"+number).show();
			}else{
				$("#amap"+i).removeClass("active").addClass("zindex10");
				$('#tab'+i).removeClass('active');
				$('#boxtab'+i).hide();
				$("#imgmap"+i).hide();
			}
		}
	}
	